# Maintainer: Daurnimator <daurnimator@archlinux.org>
# Maintainer: Sergej Pupykin <pupykin.s+arch@gmail.com>
# Contributor: Dwayne Bent <dbb.1@liqd.org>
# Contributor: Paul-Sebastian Manole <brokenthorn@gmail.com>

pkgbase=luasec
pkgname=(lua-sec lua51-sec lua52-sec lua53-sec)
epoch=2
pkgver=1.3.1
pkgrel=1
pkgdesc='Lua bindings for OpenSSL library to provide TLS/SSL communication'
arch=('loong64' 'x86_64')
url='https://github.com/brunoos/luasec/wiki'
license=('MIT')
makedepends=('luarocks'
             'lua51' 'lua52' 'lua53' 'lua') # https://github.com/luarocks/luarocks/issues/1275
depends=('openssl')
source=("$pkgbase-v$pkgver.tar.gz"::"https://github.com/brunoos/luasec/archive/v$pkgver.tar.gz")
sha512sums=('cfa4187518445abc6591bd0c24924122b62252be25ffd5564cf291f9a2ae3702a5fa299ffd265d2e0e8315b90d6783eccace4ff560f54f299161d3c5e3749508')

build() {
  cd "luasec-$pkgver"

  for v in 5.1 5.2 5.3 5.4; do
    mkdir -p "$v/"
    luarocks make --pack-binary-rock --lua-version="$v" --deps-mode=none \
      CFLAGS="$CPPFLAGS $CFLAGS -fPIC" \
      LIBFLAG="$LDFLAGS -shared" \
      luasec-"$pkgver"-1.rockspec
    mv luasec-"$pkgver"-1.*.rock "$v/"
  done
}

package_lua51-sec() {
  pkgdesc="$pkgdesc for Lua 5.1"
  depends+=('lua51-socket')
  conflicts=('luasec')
  replaces=('luasec')

  cd "luasec-$pkgver"
  luarocks install --lua-version=5.1 --tree="$pkgdir/usr/" --deps-mode=none --no-manifest 5.1/*.rock
  install -Dm644 "LICENSE" "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}

package_lua52-sec() {
  pkgdesc="$pkgdesc for Lua 5.2"
  depends+=('lua52-socket')

  cd "luasec-$pkgver"
  luarocks install --lua-version=5.2 --tree="$pkgdir/usr/" --deps-mode=none --no-manifest 5.2/*.rock
  install -Dm644 "LICENSE" "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}

package_lua53-sec() {
  pkgdesc="$pkgdesc for Lua 5.3"
  depends+=('lua53-socket')

  cd "luasec-$pkgver"
  luarocks install --lua-version=5.3 --tree="$pkgdir/usr/" --deps-mode=none --no-manifest 5.3/*.rock
  install -Dm644 "LICENSE" "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}

package_lua-sec() {
  pkgdesc="$pkgdesc for Lua 5.4"
  depends+=('lua-socket')

  cd "luasec-$pkgver"
  luarocks install --lua-version=5.4 --tree="$pkgdir/usr/" --deps-mode=none --no-manifest 5.4/*.rock
  install -Dm644 "LICENSE" "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}

# vim:set ts=2 sw=2 et:
